﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Data;
using CustomsSystem.BLL;
using CustomsSystem.Model;
using Maticsoft.Common;
using System.Web.UI.WebControls;
namespace WEB.T_bill
{
    public partial class audit : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.tbTimestart.Attributes.Add("onClick", "new WdatePicker()");
            this.tbTimestop.Attributes.Add("onClick", "new WdatePicker()");
            if (!IsPostBack)
            {
                DateTime A = new DateTime();
                A = DateTime.Today;
                tbTimestop.Text = A.AddDays(1).ToShortDateString();
                tbTimestart.Text= A.AddDays(-30).ToShortDateString();
            }
            bind();
            gridViewClass.GroupRows(gvAudit, 0, 1, 5, 4, 7);
        }


        public void bind()
        {
            DataSet ds = new DataSet();
            BillManage bll = new BillManage();
            string sql ; sql = " billTypeID=" + ddlbillTypeID.SelectedValue + "";
            if (tbTimestart.Text.Trim() != "")
            {
                //日期截止时间为空的时候，默认为现在的时间
                if (tbTimestop.Text.Trim() == "")
                {
                    DateTime timeStop = DateTime.Now;
                    sql = sql + " and inputDate between '" + tbTimestart.Text.Trim() + "' and '" + timeStop + "'";
                }
                else
                {
                    sql = sql + " and inputDate between '" + tbTimestart.Text.Trim() + "' and '" + tbTimestop.Text.Trim() + "'";
                }

            }
            sql += " and auditempid='0' ";
            sql += " order by inputDate " + ddlorder.SelectedValue;
              ds= bll.GetList(sql );
            
            gvAudit.DataSource = ds;
            gvAudit.DataBind();
            if (gvAudit.Rows.Count < 1)
                MessageBox.Show(this ,"查无数据");
        }

        /// <summary>
        /// 审核
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvAudit_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            Bill model = new Bill();
            BillManage bll = new BillManage();
            model.billTypeID = int.Parse(ddlbillTypeID.SelectedValue);
            string index = e.CommandArgument.ToString(); //那行被选中,取出选中行的索引 
            model.sheetID = int.Parse(gvAudit.Rows[int.Parse(index)].Cells [0].Text.Trim().ToString ());
           if (e.CommandName == "audit")
            {
                model.auditEmpID = Session["EmpNo"].ToString();
                model.auditdate = DateTime.Today;
                if (bll.UpdateAudit(model))
                    MessageBox.ShowAndRedirect(this, "审核成功", "audit.aspx");
                else
                    MessageBox.ShowAndRedirect(this, "审核失败", "audit.aspx");
               //Response.Write("<script>alert('')</script>");
                //Response.Redirect();
            }
           
           
           
        }










        /// <summary>
        /// 获取公司名字
        /// </summary>
        /// <returns></returns>

        public DataTable GetCID()
        {
            CustomerManage cus = new CustomerManage();
            DataSet ds = cus.GetList("");
            DataTable dt = ds.Tables[0];
            return dt;

        }

        /// <summary>
        /// 获取费用类别
        /// </summary>
        /// <returns></returns>
        public DataTable GetFeeType()
        {
            FeeTypeManage feeTypeManage = new FeeTypeManage();
            DataSet ds = feeTypeManage.GetAllList();
            DataTable dt = ds.Tables[0];
            return dt;

        }
        /// <summary>
        /// 获取人员表
        /// </summary>
        /// <returns></returns>
        public DataTable GetEmpNum()
        {
            CustomsSystem.BLL.UserManage UserManage = new UserManage();
            DataSet ds = UserManage.GetAllList();
            DataTable dt = ds.Tables[0];
            return dt;

        }

        protected void btnQuery_Click(object sender, EventArgs e)
        {
            bind();
            gridViewClass.GroupRows(gvAudit, 0, 1, 5, 4, 7);
        }
    }
}